//
//  NewFeatureView.swift
//  新浪微博
//
//  Created by 刘广东 on 16/3/4.
//  Copyright © 2016年 LGD. All rights reserved.
//

import UIKit
//新特性图像数量
private let JmNewFeatureImageCount = 4

/// 新特性视图
class NewFeatureView: UIView {


    override init(frame: CGRect) {
        super.init(frame:UIScreen.mainScreen().bounds)
        
        
        setupUI()
        
        
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    //点击屏幕
    override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
        
        //从父视图中删除
        removeFromSuperview()
    }
    
    deinit{
        
        print("\(classForCoder)\(__FUNCTION__)")
    }
}

//MARK: - 设置界面
extension NewFeatureView {
    
    private func setupUI() {
        
        //设置背景颜色
        self.backgroundColor = UIColor.whiteColor()
        //使用UIScrollView
        let scrollView = UIScrollView(frame: bounds)
        addSubview(scrollView)
        
        //添加图像
        for i in 0..<JmNewFeatureImageCount {
            
            let imageName = "new_feature_\(i + 1)"
            let iv = UIImageView(jm_imageName: imageName)
            scrollView.addSubview(iv)
            //设置Frame
            iv.frame = CGRectOffset(bounds, bounds.width * CGFloat(i), 0)
        }
        //设置contentSize
        scrollView.contentSize = CGSize(width: CGFloat (JmNewFeatureImageCount) * bounds.width, height: 0)
        //设置其他属性
        scrollView.bounces = false
        scrollView.showsHorizontalScrollIndicator = false
        scrollView.pagingEnabled = true
    }
    
}
